package {
	
	import org.flixel.*;
	
	public class DifficultySettingState extends FlxState {
		
		private var start:FlxButton, sizeup:FlxButton, sizedown:FlxButton, congup:FlxButton, congdown:FlxButton;
		private var rulestext:FlxText, sizetext:FlxText, congtext:FlxText;
		private var size:int = 16, cong:int = 6;
		
		[Embed(source = "../assets/tutorial.png")]protected var tutg:Class;
		
		public function DifficultySettingState() {
		}
		
		override public function create():void {
			rulestext = new FlxText(10, 10, FlxG.width - 19, "Game Rules:\n\n The goal of the game is to match two or more tiles vertically or horizontally (or both!) by clicking on a spot where their rows and columns intersect. If you click correctly, you've matched the tiles and they're destroyed! \n\nDestroy as many tiles as you can within the time limit but watch out! If you click improperly, your time will be reduced. The game is over when time is up.\n\nDestroy blocks faster to obtain extra combo points!\n\nGather the tile pieces and rack up extra points!");
			rulestext.alignment = "center";
			rulestext.size = 18;
			FlxG.mouse.show();
			start = new FlxButton(FlxG.width/2 - 200 , (FlxG.height*7.5)/10, "Start Game", startGame);
			
			
			sizeup = new FlxButton(FlxG.width/2 - 300 , (FlxG.height*6)/10, "size ^", adjustsizeup);
			sizedown = new FlxButton(FlxG.width/2 - 300 , (FlxG.height*6)/10 + 30, "size v", adjustsizedown);
			congup = new FlxButton(FlxG.width/2 -100  , (FlxG.height*6)/10, "congestion ^", adjustcongup);
			congdown = new FlxButton(FlxG.width/2 - 100 , (FlxG.height*6)/10  + 30, "congestion v", adjustcongdown);
			
			sizetext = new FlxText(FlxG.width / 2 - 265, ((FlxG.height * 6) / 10) + 17, FlxG.width - 19, size.toString());
			congtext = new FlxText(FlxG.width/2 - 65 , (FlxG.height*6)/10  + 17, FlxG.width - 19, cong.toString());
			
			var tutorialImg:FlxSprite = new FlxSprite(400, 350);
			tutorialImg.loadGraphic(tutg, false, false, 199, 264);

			add(sizeup);
			add(sizedown);
			add(congup);
			add(congdown);
			add(start);
			add(rulestext);
			add(sizetext);
			add(congtext);
			add(tutorialImg);
			super.create();
			
		}
		
		private function startGame():void {
			//FlxG.mouse.hide();
			FlxG.switchState(new PlayBoardState(size, cong, 220));
		}
		private function adjustsizeup():void {
			if (size < 19) size++;
			sizetext.text = size.toString();
		}
		private function adjustsizedown():void {
			if (size > 5) size--;
			
			sizetext.text = size.toString();
		}
		private function adjustcongup():void {
			if(cong < 9)cong++;
			congtext.text = cong.toString();
		}
		private function adjustcongdown():void {
			if(cong>1)cong--;
			congtext.text = cong.toString();
		}
		
	}
	
	
}